/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sca;

import br.com.sca.interfaces.AlunoFrame;
import br.com.sca.interfaces.CarterinhaFrame;
import br.com.sca.interfaces.CarterinhasVencidasFrame;
import br.com.sca.interfaces.ConvenioFrame;
import br.com.sca.interfaces.ConveniosAtivosFrame;
import br.com.sca.interfaces.EmpresaFrame;
import br.com.sca.interfaces.EscolaFrame;
import br.com.sca.interfaces.LoginFrame;
import br.com.sca.util.AcessoBD;
import java.awt.Frame;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Leonir
 */
public class SistemaCadastroAluno extends javax.swing.JFrame {

    public SistemaCadastroAluno() {
        initComponents();

        setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
        setLocationRelativeTo(null);
    }

    private void centralizaFormulario(JInternalFrame internalFrame) {
        internalFrame.setLocation((this.getWidth() - internalFrame.getWidth()) / 2, ((this.getHeight() - internalFrame.getHeight()) / 2) - 20);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        DesktopPane = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnSistema = new javax.swing.JMenu();
        mnItSair = new javax.swing.JMenuItem();
        mnCadastros = new javax.swing.JMenu();
        mnItAluno = new javax.swing.JMenuItem();
        mnUsuario = new javax.swing.JMenuItem();
        mnEmpresas = new javax.swing.JMenuItem();
        mnEscola = new javax.swing.JMenuItem();
        mnLancamento = new javax.swing.JMenu();
        mnCarterinha = new javax.swing.JMenuItem();
        mnConvenio = new javax.swing.JMenuItem();
        mnRelatorios = new javax.swing.JMenu();
        mnCarterinhasVencidas = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema de Cadastro de Alunos");
        getContentPane().setLayout(new java.awt.CardLayout());

        DesktopPane.setBackground(new java.awt.Color(204, 204, 204));

        javax.swing.GroupLayout DesktopPaneLayout = new javax.swing.GroupLayout(DesktopPane);
        DesktopPane.setLayout(DesktopPaneLayout);
        DesktopPaneLayout.setHorizontalGroup(
            DesktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        DesktopPaneLayout.setVerticalGroup(
            DesktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        getContentPane().add(DesktopPane, "card2");

        mnSistema.setText("Sistema");

        mnItSair.setText("Sair");
        mnItSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnItSairActionPerformed(evt);
            }
        });
        mnSistema.add(mnItSair);

        jMenuBar1.add(mnSistema);

        mnCadastros.setText("Cadastros");

        mnItAluno.setText("Alunos");
        mnItAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnItAlunoActionPerformed(evt);
            }
        });
        mnCadastros.add(mnItAluno);

        mnUsuario.setText("Usuários");
        mnUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnUsuarioActionPerformed(evt);
            }
        });
        mnCadastros.add(mnUsuario);

        mnEmpresas.setText("Empresas");
        mnEmpresas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnEmpresasActionPerformed(evt);
            }
        });
        mnCadastros.add(mnEmpresas);

        mnEscola.setText("Escolas");
        mnEscola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnEscolaActionPerformed(evt);
            }
        });
        mnCadastros.add(mnEscola);

        jMenuBar1.add(mnCadastros);

        mnLancamento.setText("Lançamento");

        mnCarterinha.setText("Carterinhas");
        mnCarterinha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCarterinhaActionPerformed(evt);
            }
        });
        mnLancamento.add(mnCarterinha);

        mnConvenio.setText("Convênios");
        mnConvenio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnConvenioActionPerformed(evt);
            }
        });
        mnLancamento.add(mnConvenio);

        jMenuBar1.add(mnLancamento);

        mnRelatorios.setText("Relatórios");

        mnCarterinhasVencidas.setText("Carteirinhas Vencidas");
        mnCarterinhasVencidas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCarterinhasVencidasActionPerformed(evt);
            }
        });
        mnRelatorios.add(mnCarterinhasVencidas);

        jMenuItem1.setText("Convênios Ativos");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mnRelatorios.add(jMenuItem1);

        jMenuItem2.setText("Lista de Alunos Cadastrados");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        mnRelatorios.add(jMenuItem2);

        jMenuBar1.add(mnRelatorios);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnItSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnItSairActionPerformed
        String args[] = {""};
        LoginTela.main(args);
        //System.exit(0);
        dispose();

    }//GEN-LAST:event_mnItSairActionPerformed

    private void mnItAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnItAlunoActionPerformed
        AlunoFrame alunoFrame = new AlunoFrame();
        DesktopPane.add(alunoFrame);
        alunoFrame.setVisible(true);
        centralizaFormulario(alunoFrame);
    }//GEN-LAST:event_mnItAlunoActionPerformed

    private void mnUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnUsuarioActionPerformed
        LoginFrame loginFrame = new LoginFrame();
        DesktopPane.add(loginFrame);
        loginFrame.setVisible(true);
        centralizaFormulario(loginFrame);
    }//GEN-LAST:event_mnUsuarioActionPerformed

    private void mnEmpresasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnEmpresasActionPerformed
        EmpresaFrame empresaFrame = new EmpresaFrame();
        DesktopPane.add(empresaFrame);
        empresaFrame.setVisible(true);
        centralizaFormulario(empresaFrame);
    }//GEN-LAST:event_mnEmpresasActionPerformed

    private void mnEscolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnEscolaActionPerformed
        EscolaFrame escolaFrame = new EscolaFrame();
        DesktopPane.add(escolaFrame);
        escolaFrame.setVisible(true);
        centralizaFormulario(escolaFrame);
    }//GEN-LAST:event_mnEscolaActionPerformed

    private void mnConvenioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnConvenioActionPerformed
        ConvenioFrame convenioFrame = new ConvenioFrame();
        convenioFrame.setVisible(true);
        DesktopPane.add(convenioFrame);
        centralizaFormulario(convenioFrame);
    }//GEN-LAST:event_mnConvenioActionPerformed

    private void mnCarterinhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCarterinhaActionPerformed
        CarterinhaFrame carterinhaFrame = new CarterinhaFrame();
        carterinhaFrame.setVisible(true);
        DesktopPane.add(carterinhaFrame);
        centralizaFormulario(carterinhaFrame);
    }//GEN-LAST:event_mnCarterinhaActionPerformed

    private void mnCarterinhasVencidasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCarterinhasVencidasActionPerformed
        CarterinhasVencidasFrame cvf = new CarterinhasVencidasFrame();
        cvf.setVisible(true);
        DesktopPane.add(cvf);
        centralizaFormulario(cvf);
    }//GEN-LAST:event_mnCarterinhasVencidasActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        /* ConveniosAtivosFrame caf = new ConveniosAtivosFrame();
         caf.setVisible(true);
         DesktopPane.add(caf);
         centralizaFormulario(caf);*/
        AcessoBD conexao = new AcessoBD();
        try {
            HashMap parametros = new HashMap();
            parametros.put("DATA_ATUAL", new Date());
            parametros.put("IMAGEM", System.getProperty("user.dir") + "\\img\\logo2.jpg");
            JasperPrint jp = JasperFillManager.fillReport(System.getProperty("user.dir") + "\\relatorios\\ConveniosAtivos.jasper", parametros, conexao.getConexao());
            JasperViewer jv = new JasperViewer(jp, false);
            jv.setExtendedState(Frame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        } catch (JRException ex) {
            System.out.println("JRException " + ex.getMessage());
            Logger.getLogger(ConveniosAtivosFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            System.out.println("SQLException " + ex.getMessage());
            Logger.getLogger(ConveniosAtivosFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        AcessoBD conexao = new AcessoBD();
        try {
            HashMap parametros = new HashMap();
            parametros.put("IMAGEM", System.getProperty("user.dir") + "\\img\\logo2.jpg");
            JasperPrint jp = JasperFillManager.fillReport(System.getProperty("user.dir") + "\\relatorios\\ListaAlunosCadastrado.jasper", parametros, conexao.getConexao());
            JasperViewer jv = new JasperViewer(jp, false);
            jv.setExtendedState(Frame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        } catch (JRException ex) {
            System.out.println("JRException " + ex.getMessage());
            Logger.getLogger(ConveniosAtivosFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            System.out.println("SQLException " + ex.getMessage());
            Logger.getLogger(ConveniosAtivosFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SistemaCadastroAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SistemaCadastroAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SistemaCadastroAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SistemaCadastroAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SistemaCadastroAluno().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane DesktopPane;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenu mnCadastros;
    private javax.swing.JMenuItem mnCarterinha;
    private javax.swing.JMenuItem mnCarterinhasVencidas;
    private javax.swing.JMenuItem mnConvenio;
    private javax.swing.JMenuItem mnEmpresas;
    private javax.swing.JMenuItem mnEscola;
    private javax.swing.JMenuItem mnItAluno;
    private javax.swing.JMenuItem mnItSair;
    private javax.swing.JMenu mnLancamento;
    private javax.swing.JMenu mnRelatorios;
    private javax.swing.JMenu mnSistema;
    private javax.swing.JMenuItem mnUsuario;
    // End of variables declaration//GEN-END:variables
}
